package com.hxd.otc.module.my.model;

import com.hxd.otc.api.IExchangeApi;
import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.my.bean.BaseListBean;
import com.hxd.otc.module.my.bean.ExchangeRecordBean;
import com.hxd.otc.module.my.bean.ExchangeRuleBean;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.net.RetrofitManager;
import com.uber.autodispose.AutoDisposeConverter;

import java.util.ArrayList;

import io.reactivex.android.schedulers.AndroidSchedulers;

/**
 * Created by lzy on 2018/12/27 0027.
 * description ${兑换model}
 */
public class ExchangeModel {

    private static class SingletonHolder {
        private static final ExchangeModel instance = new ExchangeModel();
    }

    public static ExchangeModel getInstance() {
        return ExchangeModel.SingletonHolder.instance;
    }

    /**
     * 获取兑换币种规则信息
     */
    public void exchangeCoinRule(BaseObserver<ArrayList<ExchangeRuleBean>> observer, AutoDisposeConverter<BaseBean<ArrayList<ExchangeRuleBean>>> converter) {
        getExchangeApi().exchangeCoinRule()
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**
     * 订单列表
     *
     * @param showCount
     * @param currentPage
     */
    public void exchangeList(String showCount, String currentPage, BaseObserver<BaseListBean<ExchangeRecordBean>> observer,
                             AutoDisposeConverter<BaseBean<BaseListBean<ExchangeRecordBean>>> converter) {
        getExchangeApi().exchangeList(showCount, currentPage)
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**
     * 获取兑换详情
     *
     * @param orderId 订单id
     */
    public void queryOrderDetail(String orderId, BaseObserver<ExchangeRecordBean> observer,
                                 AutoDisposeConverter<BaseBean<ExchangeRecordBean>> converter) {
        getExchangeApi().queryOrderDetail(orderId)
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**
     * 获取兑换汇率
     *
     * @param outSymbol 转出币种名称
     * @param inSymbol  转入币种名称
     */
    public void exchangeTax(String outSymbol, String inSymbol, BaseObserver<String> observer, AutoDisposeConverter<BaseBean<String>> converter) {
        getExchangeApi().exchangeTax(outSymbol, inSymbol)
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**
     * 兑换
     *
     * @param outSymbol 转出币种ID
     * @param inSymbol  转入币种ID
     * @param outVolume 转出币种数量
     */
    public void exchangePay(String outSymbol, String inSymbol, String outVolume,
                            BaseObserver<ExchangeRecordBean> observer, AutoDisposeConverter<BaseBean<ExchangeRecordBean>> converter) {
        getExchangeApi().exchangePay(outSymbol, inSymbol, outVolume)
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    private IExchangeApi getExchangeApi() {
        return RetrofitManager.getDefault().create(IExchangeApi.class);
    }
}
